package conlon.seata01.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import conlon.api.Seata02Api;
import conlon.api.form.AccountForm;
import conlon.api.form.StoreForm;
import conlon.seata01.dao.OrderDao;
import conlon.seata01.entity.OrderEntity;
import conlon.seata01.service.OrderService;
import conlon.utils.SnowflakeIdWorker;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 用户信息 服务实现类
 * </p>
 *
 * @author conlon
 * @since 2021-08-16
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderDao, OrderEntity> implements OrderService {

    @Autowired
    private Seata02Api seata02Api;


    @Override
    @GlobalTransactional
    @Transactional(rollbackFor = Exception.class)
    public void createOrder() {
        OrderEntity orderEntity = new OrderEntity();
        orderEntity
                .setId(SnowflakeIdWorker.generateId())
                .setOrderName("orderName01")
        ;
        // 保存订单
        this.save(orderEntity);
        // 保存账单
        seata02Api.createAccount(new AccountForm().setAccountId(640347335132143616L).setAccountName("accountName01"));
        // 保存仓库
        seata02Api.createStore(new StoreForm().setId(SnowflakeIdWorker.generateId()).setStoreName("storeName01"));
    }
}
